package com.wondedDream.controller.admin;

import com.wondedDream.model.MockExam;
import com.wondedDream.model.MockExamQuestion;
import com.wondedDream.service.MockExamQuestionService;
import com.wondedDream.util.HtmlCrawler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController(value = "adminMockExamQuestionController")
@RequestMapping("/api/mockExamQuestions")
@Api(description = "管理端-模考详情信息")
public class MockExamQuestionController {

    @Autowired
    private MockExamQuestionService mockExamQuestionService;


    // 创建新的模考问题
    @PostMapping("/")
    @ApiOperation(value = "创建新的模考问题")
    public MockExamQuestion createMockExamQuestion(@RequestBody MockExamQuestion question) {
        return mockExamQuestionService.saveMockExamQuestion(question);
    }


    // 创建新的模考问题
    @PostMapping("/createMockExamQuestionByFileJson")
    @ApiOperation(value = "根据文件导入模考题库")
    public String createMockExamQuestionByFileJson() {
        mockExamQuestionService.createMockExamQuestionByFileJson();
        return "success";
    }

    // 根据id删除模考问题
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除模考问题")
    public void deleteMockExamQuestion(@PathVariable Integer id) {
        mockExamQuestionService.deleteMockExamQuestion(id);
    }


    // 根据id修改模考问题
    @PutMapping("/{id}")
    @ApiOperation(value = "根据id修改模考问题")
    public MockExamQuestion updateMockExamQuestion(@PathVariable Integer id, @RequestBody MockExamQuestion mockExamQuestion) {
        mockExamQuestion.setId(id);
        return mockExamQuestionService.updateMockExamQuestion(mockExamQuestion);
    }

    // 获取模考问题信息
    @GetMapping("/{id}")
    @ApiOperation(value = "获取模考问题信息")
    public MockExamQuestion getMockExamQuestionById(@PathVariable Integer id) {
        return mockExamQuestionService.getMockExamQuestionById(id);
    }

    // 获取某一模考下的模考问题列表
    @GetMapping("/byMockExam/{mockExamId}")
    @ApiOperation(value = "获取某一模考下的模考问题列表")
    public List<MockExamQuestion> getMockExamQuestionsByMockExamId(@PathVariable Integer mockExamId) {
        return mockExamQuestionService.getMockExamQuestionsByMockExamId(mockExamId);
    }
}